#include <iostream>
using std::cout;
using std::endl;

class Base{
public:
    Base(long x)
    : _base(x)
    {}

    virtual void display() const{
        cout << "Base::display()" << endl;
    }

    //Base定义了多个虚函数，但仍然只有一个虚函数指针
    //只有一张虚函数表
    //这张虚函数表中存放多个虚函数的入口地址
    virtual void print() const{
        cout << "Base::print()" << endl;
    }
private:
    long _base;
};


class Derived
: public Base
{
public:
    Derived(long base,long derived)
    : Base(base)
    , _derived(derived)
    {}

    //Derived类同样只有一张虚函数表
    //
    //如果Derived类继承多个有虚函数的基类
    //那么Derived类才会有多张虚表
    void display() const override{
        cout << "Derived::display()" << endl;
    }
private:
    long _derived;
};

void test0(){
    cout << sizeof(Base) << endl;
    cout << sizeof(Derived) << endl;
    cout << endl;


    Derived d1(2,5);
    Base * pb = &d1;
    pb->display();

    Base base(10);
    Base * pb2 = &base;
    pb2->display();
}

int main(void){
    test0();
    return 0;
}
